# -*- coding: utf-8 -*-
# encoding:utf-8

from db import ZhiHuUser,engine
from sqlalchemy.orm import scoped_session, sessionmaker
import redis

red = redis.Redis(host='localhost', port=6379, db=1)
red_queue = "the_test_the_url_queue"
red_crawled_set = "the_test_url_has_crawled"
back = "back"

db = scoped_session(sessionmaker(bind=engine,autocommit=False, autoflush=True,expire_on_commit=False))


def write_to_redis():
	result = db.query(ZhiHuUser).all()
	for i in result:
		red.sadd(back,i.user_url)
	print "write_to_redis_ok"

def change_set_to_list():
	mem = red.smembers("now")
	for i in mem:
		red.lpush(red_queue,i)

def main():
	# write_to_redis()
	change_set_to_list()
if __name__ == '__main__':
	main()

